<?php
/**
 * Created by PhpStorm.
 * User: beijingwhg
 * Date: 2017/5/12
 * Time: 下午3:06
 */

namespace App\Http\Controllers\Admin;


use App\Http\Controllers\Controller;
use App\Models\NotificationModel;

class NotifyController extends Controller
{
    protected $notify;

    public function __construct(NotificationModel $model)
    {
        $this->notify = $model;
    }

    public function index($type = 'unread')
    {
        return $this->$type();
    }

    public function unread()
    {
        $notifies = $this->notify->where(['id'=>admin()->admin_id, 'to'=>'admin', 'status'=>0])->orderBy('created_at', 'desc')->limit(10)->get();

        $unread = 1;

        return view('admin.notification', compact('notifies', 'unread'));
    }

    public function all()
    {
        $notifies = $this->notify->where(['id'=>admin()->admin_id, 'to'=>'admin'])->orderBy('created_at', 'desc')->limit(10)->get();

        $unread = 0;

        return view('admin.notification', compact('notifies', 'unread'));
    }
}